# -*- coding: utf-8 -*-
"""
Created on Fri Jan 01 16:00:49 2016

@author: wuyf
"""
from gauss import*
import Tkinter
from Tkinter import *
#import tkMessageBox

root = Tkinter.Tk()
def cb_project():
    latitude = float(input_lat.get())
    longitude = float(input_lon.get())
    
    x,y = Gauss(longitude,latitude)
    #print x
    text_x.set(str(x))
    text_y.set(str(y))
    #input_x.set('123')
    
#=====================================================
def draw_lat_lon_lines(canvas,lat_line_num,lon_line_num):
    lat_line_num_f = float(lat_line_num)
    lon_line_num_f = float(lon_line_num)
    margin = float(25)
    height = float(400)
    width = float(600)
    
    v_gap = float((height-2*margin)/(lat_line_num_f-1))
    h_gap = float((width-2*margin)/(lon_line_num_f-1))
    
    print h_gap
    for j in range(0,lat_line_num+1):
        v_coor = margin + (lat_line_num-j)*v_gap
        canvas.create_line(margin,v_coor,width-margin,v_coor)
        
    for i in range(0,lon_line_num):
        h_coor = margin + i*h_gap
        canvas.create_line(h_coor,margin,h_coor,height-margin)
        
    canvas.create_text(20,10,text = '左上')
    canvas.create_text(20,360,text = '左下1')
    canvas.create_text(40,390,text = '左下2')
    canvas.create_text(560,390,text = '右下')
#=====================================================
def cb_drawgrid():
    draw_lat_lon_lines(canvas,12,8)
#=====================================================
#the frame that input the lat and y
frame_lat_y = Frame(root)

label_lat = Tkinter.Label(frame_lat_y,text='纬度')
label_lat.pack(side = LEFT)

input_lat = Entry(frame_lat_y,bd=5)
input_lat.pack(side = LEFT)


label_y = Tkinter.Label(frame_lat_y,text='X')
label_y.pack(side = LEFT)

text_y = StringVar()
input_y = Entry(frame_lat_y,bd=5,textvariable = text_y)
input_y.pack(side = LEFT)

frame_lat_y.pack(side = TOP)
#=====================================================
#the frame that input the lon and x
frame_lon_x = Frame(root)

label_lon = Tkinter.Label(frame_lon_x,text='经度')
label_lon.pack(side = LEFT)



input_lon = Entry(frame_lon_x,bd=5)
input_lon.pack(side = LEFT)

label_x = Tkinter.Label(frame_lon_x,text='Y')
label_x.pack(side = LEFT)

text_x = StringVar()
input_x = Entry(frame_lon_x,bd=5,textvariable = text_x)
input_x.pack(side = LEFT)

frame_lon_x.pack(side = TOP)
#====================================================
#the frame that contains two button(project and local grid)
frame_pro_grid = Frame(root)
project = Tkinter.Button(frame_pro_grid,text ='计算投影坐标',command = cb_project)
project.pack(side = LEFT)

grid = Tkinter.Button(frame_pro_grid,text ='局部坐标网格',command = cb_drawgrid)
grid.pack(side = LEFT)

frame_pro_grid.pack(side = TOP)
#====================================================
#the frame that contains the canvas
frame_canvas = Frame(root)

canvas = Canvas(frame_canvas,bg='white',height='400',width='600')
canvas.pack(side = TOP)



frame_canvas.pack(side = TOP)
#====================================================
root.mainloop()
